﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using BangleCMS.Common;
using BangleCMS.Model;
namespace BangleCMS.BLL
{
    //t_webnav
    public partial class t_webnavBLL
    {

        private readonly BangleCMS.DAL.t_webnavDAL dal = new BangleCMS.DAL.t_webnavDAL();
        public t_webnavBLL()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int WebNavId)
        {
            return dal.Exists(WebNavId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BangleCMS.Model.t_webnav model)
        {
            return dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BangleCMS.Model.t_webnav model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int WebNavId)
        {

            return dal.Delete(WebNavId);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string WebNavIdlist)
        {
            return dal.DeleteList(WebNavIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BangleCMS.Model.t_webnav GetModel(int WebNavId)
        {

            return dal.GetModel(WebNavId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BangleCMS.Model.t_webnav> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BangleCMS.Model.t_webnav> DataTableToList(DataTable dt)
        {
            List<BangleCMS.Model.t_webnav> modelList = new List<BangleCMS.Model.t_webnav>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BangleCMS.Model.t_webnav model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BangleCMS.Model.t_webnav();
                    if (dt.Rows[n]["WebNavId"].ToString() != "")
                    {
                        model.WebNavId = int.Parse(dt.Rows[n]["WebNavId"].ToString());
                    }
                    if (dt.Rows[n]["ParentId"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["ParentId"].ToString());
                    }
                    model.Title = dt.Rows[n]["Title"].ToString();
                    model.Code = dt.Rows[n]["Code"].ToString();
                    if (dt.Rows[n]["IsSys"].ToString() != "")
                    {
                        model.IsSys = int.Parse(dt.Rows[n]["IsSys"].ToString());
                    }
                    model.Href = dt.Rows[n]["Href"].ToString();
                    model.OrderNo = dt.Rows[n]["OrderNo"].ToString();
                    model.CreateTime = dt.Rows[n]["CreateTime"].ToString();
                    if (dt.Rows[n]["CreateUserId"].ToString() != "")
                    {
                        model.CreateUserId = int.Parse(dt.Rows[n]["CreateUserId"].ToString());
                    }
                    model.UpdateTime = dt.Rows[n]["UpdateTime"].ToString();
                    if (dt.Rows[n]["UpdateUserId"].ToString() != "")
                    {
                        model.UpdateUserId = int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
                    }
                    if (dt.Rows[n]["Valid"].ToString() != "")
                    {
                        model.Valid = int.Parse(dt.Rows[n]["Valid"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion

    }
}